class Feed::MoneyGift < Feed
  
  validates_presence_of :added_money
  validates_presence_of :user_id,
    :money,
    :info_id    
  validates_uniqueness_of :info_id, :scope => :user_id
    
  def before_create
    self.version = 1
    self.added_money = info.money
    self.money = user.money + info.money
  end
  
  def after_create
    user.money += added_money
    user.save(false)
  end
  
  # to template
  def to_t
    ":user于:created_at_ago_in_words前:link_to_gift了:added_money麦粒的大礼包"
  end
end